package com.nondo.rdp.auth.domain;

import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Index;
import javax.persistence.Table;
import javax.persistence.Transient;
import javax.validation.constraints.NotNull;

import org.hibernate.validator.constraints.Length;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonSetter;
import com.nondo.rdp.core.domain.base.BaseEntity;

/**
 * 我的-消息中心
 */
@Entity
@Table(name = "sys_message", indexes = { @Index(columnList = "type,title") })
public class Message extends BaseEntity {
	private static final long serialVersionUID = -4820694000557597176L;
	private Long id; // 主键ID
	private Integer type; // 0：系统；1：关注；2：评论
	private String title; // 标题
	private String content; // 内容
	private String method; // 公告，课程，分析，资讯，答疑
	private String extra; // 调用参数
	private Date publishDate; // 发布日期

	// 扩展字段
	private String icon; // 类型图标
	private Long umid; // 关联表主键
	private String uids;// 接收用户id，用逗号隔开

	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	@NotNull(message = "标题不能为空")
	@Length(min = 1, max = 32, message = "标题长度不能超过32个字符")
	@Column(name = "title", length = 32)
	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	@NotNull(message = "内容不能为空")
	@Column(name = "content", columnDefinition = "text")
	public String getContent() {
		return content;
	}

	public void setContent(String content) {
		this.content = content;
	}

	@Column(columnDefinition = "int default 0", nullable = false)
	public Integer getType() {
		return type;
	}

	public void setType(Integer type) {
		this.type = type;
	}

	public String getMethod() {
		return method;
	}

	public void setMethod(String method) {
		this.method = method;
	}

	public String getExtra() {
		return extra;
	}

	public void setExtra(String extra) {
		this.extra = extra;
	}
	
	@JsonFormat( pattern = "yyyy-MM-dd HH:mm")
	public Date getPublishDate() {
		return publishDate;
	}

	public void setPublishDate(Date publishDate) {
		this.publishDate = publishDate;
	}

	@JsonIgnore
	@Transient
	public Long getUmid() {
		return umid;
	}

	@JsonSetter
	public void setUmid(Long umid) {
		this.umid = umid;
	}

	@JsonIgnore
	@Transient
	public String getUids() {
		return uids;
	}

	@JsonSetter
	public void setUids(String uids) {
		this.uids = uids;
	}

	@Transient
	public String getIcon() {
		return icon;
	}

	public void setIcon(String icon) {
		this.icon = icon;
	}

}
